import Vue from "vue"
import VueI18n from "vue-i18n"
//引入自定义语言配置  
import zh from './langs/zh'
import en from './langs/en'
//引入UI框架语言配置---elementui
import ElementLocale from 'element-ui/lib/locale'
import enLocale from 'element-ui/lib/locale/lang/en' // 引入饿了么的英文包
import zhLocale from 'element-ui/lib/locale/lang/zh-CN' // 引入饿了么的中文包
 
ElementLocale.i18n((key, value) => i18n.t(key, value)) 
Vue.use(VueI18n);
 
 // 各个国家的key
const localeKeys = ['en', 'zh']

// 各个国家语言包
const messages = {}
for (const key of localeKeys) {
  // messages[key] = require(`./langs/${key}.js`).default
  const langObj = require(`./langs/${key}.js`).default
  const langElement = require(`./element/${key}`)
  messages[key] = {
    ...langObj,
    ...langElement ? langElement.default : {}
  }

}

const i18n = new VueI18n({
  locale: localStorage.getItem('change-language') || 'zh',
  messages,
  silentTranslationWarn: true // 忽略翻译警告
})

// const i18n = new VueI18n({
//     locale: localStorage.getItem('lang') || "en", 
//     messages: {
//         // 中文语言包
//         'zh': {
//             ...zh,
//             ...zhLocale
//         },
//         //英文语言包
//         'en': {
//             ...en,
//             ...enLocale
//         }
//     },
//     globalInjection: true, 
//     fallbackLocale: 'en', 
// });
 
export default i18n